package com.sgb.goods.viewmodel.publish;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.AlbumEntity;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GoodsAlbumModel extends BaseViewModel {

    public ObservableField<Map> map = new ObservableField<>(new HashMap());
    public MutableLiveData<List<AlbumEntity>> albumListLD = new MutableLiveData<>();
    private int page = 1;
    private int size = 10;

    public void getSupplierPhotosByAlbumId(boolean isLoadMore,String id) {
        page = isLoadMore ? page + 1 : 1;
        map.get().put("page", page);
        map.get().put("limit", size);
        map.get().put("companyNo", SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, ""));
        map.get().put("userNo", SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.USER_NO, ""));
        showLoading();
        GoodsNet.getInstance().getGoodsPublishApi().getSupplierPhotosByAlbumId(id).enqueue(new GoodsCallBack<BaseEntity<List<AlbumEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<AlbumEntity>> data) {
                albumListLD.setValue(data.getData());
            }
        });
    }

}
